package com.allen.workflow.listener.task;

import com.allen.workflow.WfLogUtils;
import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.delegate.TaskListener;

/**
 * @program: spring-boot-demo
 * @className BusinessTaskListener
 * @description: 任务监听器封装
 * @author: zp
 * @create: 2024-08-16 14:35
 * @Version 1.0
 **/
public abstract class BusinessTaskListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        WorkTask workTask = new WorkTask(delegateTask);
        process(workTask);
    }

    /**
     * 描述
     *
     * @param workTask
     * @return void
     * @author zp
     * @date 2024/8/16 14:40
     */
    protected void process(WorkTask workTask) {
        String eventName = workTask.getEventName();
        WfLogUtils.printLog(eventName, workTask);
        switch (eventName) {
            case TaskListener.EVENTNAME_CREATE:
                onCreate(workTask);
                break;
            case TaskListener.EVENTNAME_COMPLETE:
                onComplete(workTask);
                break;
            case TaskListener.EVENTNAME_ASSIGNMENT:
                onAssignment(workTask);
                break;
            case TaskListener.EVENTNAME_DELETE:
                onDelete(workTask);
                break;
            case TaskListener.EVENTNAME_UPDATE:
                onUpdate(workTask);
                break;
            case TaskListener.EVENTNAME_TIMEOUT:
                onTimeout(workTask);
                break;
            default:
                break;
        }
    }


    protected abstract void onCreate(WorkTask delegateTask);

    protected abstract void onComplete(WorkTask delegateTask);

    protected abstract void onAssignment(WorkTask delegateTask);

    protected abstract void onDelete(WorkTask delegateTask);

    protected abstract void onUpdate(WorkTask delegateTask);

    protected abstract void onTimeout(WorkTask delegateTask);

}
